package com.briup.sms.utils;

import lombok.AllArgsConstructor;
import lombok.Data;

/**
 * 统一响应格式
 */
@AllArgsConstructor
@Data
public class Result<T> {
    private int  code;
    private String message;
    private T data;

    public Result(ResultCode resultCode){
        this.code=resultCode.code();
        this.message=resultCode.message();
    }

    public  Result(ResultCode resultCode, T data) {
        this(resultCode);
        this.data=data;
    }

    static public Result error(ResultCode resultCode){
        return  new Result(resultCode);
    }

    static public Result success(){
        return  new Result(ResultCode.SUCCESS);
    }
    static public<T> Result success(T data){
        return  new Result(ResultCode.SUCCESS,data);
    }
}
